package com.dxt.rabbitmq.controller;

import com.dxt.rabbitmq.service.DelayAndDead.DADPublisher;
import com.dxt.rabbitmq.service.ack.AckPublisher;
import com.dxt.rabbitmq.service.callback.ConfirmAndReturnPublisher;
import com.dxt.rabbitmq.service.direct.DirectModePublisher;
import com.dxt.rabbitmq.service.fanout.FanoutModePublisher;
import com.dxt.rabbitmq.service.topic.TopicModePublisher;
import com.dxt.rabbitmq.vo.TestMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rabbitmq")
public class MQController {

    @Autowired
    private DirectModePublisher basicQueuePublisher;

    @Autowired
    private FanoutModePublisher fanoutModePublisher;

    @Autowired
    private TopicModePublisher topicModePublisher;

    @Autowired
    private ConfirmAndReturnPublisher confirmAndReturnPublisher;

    @Autowired
    private AckPublisher ackPublisher;

    @Autowired
    private DADPublisher dadPublisher;

    @PostMapping("/basic")
    public String basicMode(@RequestBody TestMessage testMessage){
        System.out.println("begin ...");
        basicQueuePublisher.send(testMessage);
        return "success";
    }

    @PostMapping("/fanout")
    public String fanoutMode(@RequestBody TestMessage testMessage){
        System.out.println("begin ...");
        fanoutModePublisher.publish(testMessage);
        return "success";
    }

    @PostMapping("/topic")
    public String topicMode(@RequestBody TestMessage testMessage){
        System.out.println("begin ...");
        topicModePublisher.publish(testMessage);
        return "success";
    }

    @RequestMapping("/confirm")
    public String confirmAndReturn(@RequestBody TestMessage testMessage){
        System.out.println("begin ...");
        confirmAndReturnPublisher.publish(testMessage);
        return "success";
    }

    @RequestMapping("/ack")
    public String consumerAck(@RequestBody TestMessage testMessage){
        System.out.println("begin ...");
        ackPublisher.publish(testMessage);
        return "success";
    }

    @RequestMapping("/dad")
    public String delayAndDeadQueue(@RequestBody TestMessage testMessage){
        System.out.println("begin ...");
        dadPublisher.publish(testMessage);
        return "success";
    }
}
